#ifndef _3DES_H
#define _3DES_H

typedef struct
{
    unsigned long esk[32];     /* DES encryption subkeys */
    unsigned long dsk[32];     /* DES decryption subkeys */
}
des_context;

typedef struct
{
    unsigned long esk[96];     /* Triple-DES encryption subkeys */
    unsigned long dsk[96];     /* Triple-DES decryption subkeys */
}
des3_context;

class C3Des  
{
public:
	C3Des();
	virtual ~C3Des();
	void des_main_ks( unsigned long SK[32], unsigned char key[8] );
	void des_crypt( unsigned long SK[32], unsigned char input[8], unsigned char output[8] );
	void des3_crypt( unsigned long SK[96], unsigned char input[8], unsigned char output[8] );

/*
 * DES key schedule
 */
	void desSetKey(des_context *ctx, unsigned char key[8] );

/*
 * DES 64-bit block encryption (ECB)
 */
	void desEncrypt(unsigned char *key, unsigned char input[8], 
		unsigned char output[8] );

/*
 * DES 64-bit block decryption (ECB)
 */
	void desDecrypt(unsigned char *key, unsigned char input[8], 
		unsigned char output[8] );

/*
 * DES-CBC encryption
 */
	void desCBCEncrypt( des_context *ctx, unsigned char iv[8],
                      unsigned char *input, unsigned char *output, unsigned int len );

/*
 * DES-CBC decryption
 */
	void desCBCDecrypt( des_context *ctx, unsigned char iv[8],
                      unsigned char *input, unsigned char *output, unsigned int len );

/*
 * Triple-DES key schedule (112-bit)
 */
	void des3_set_2keys( des3_context *ctx, unsigned char key[16] );

/*
 * Triple-DES key schedule (168-bit)
 */
	void des3_set_3keys( des3_context *ctx, unsigned char key[24] );

/*
 * Triple-DES 64-bit block encryption (ECB)
 */
//extern void des3_encrypt( des3_context *ctx, uchar input[8], uchar output[8] );
	void des3Encrypt(unsigned char *key, unsigned char input[8], unsigned char output[8]);

/*
 * Triple-DES 64-bit block decryption (ECB)
 */
//extern void des3_decrypt( des3_context *ctx, uchar input[8], uchar output[8] );
	void des3Decrypt(unsigned char *key, unsigned char input[8], unsigned char output[8] );

/*
 * 3DES-CBC encryption
extern void des3_cbc_encrypt( des3_context *ctx, uchar iv[8],
                       uchar *input, uchar *output, uint len );
*/
	void des3CBCEncrypt( des3_context *ctx, unsigned char iv[8],
                       unsigned char *input, unsigned char *output, unsigned int len );

/*
 * 3DES-CBC decryption
 */
	void des3CBCDecrypt( des3_context *ctx, unsigned char iv[8],
                       unsigned char *input, unsigned char *output, unsigned int len );

};

#endif

